﻿using Microsoft.EntityFrameworkCore;

namespace Devonline.Entity;

/// <summary>
/// 组织单位
/// </summary>
[Table("organization"), DisplayName("组织单位"), Index(nameof(Name), IsUnique = true), Index(nameof(Code), IsUnique = true)]
public class Organization : Organization<string>, IIdentity, IParent, IEntitySetWithCreateAndUpdate
{
    /// <summary>
    /// 上级组织
    /// </summary>
    public virtual Organization? Parent { get; set; }
    /// <summary>
    /// 组织级别
    /// </summary>
    public virtual Level? Level { get; set; }
    /// <summary>
    /// 所在区域
    /// </summary>
    public virtual Region? Region { get; set; }
    /// <summary>
    /// 单位证件
    /// </summary>
    public virtual Credential? Credential { get; set; }
    /// <summary>
    /// 通用附件集合, NotMapped Attachments 用于记录实体对象上上传的附件
    /// </summary>
    [NotMapped]
    public virtual ICollection<Attachment>? Attachments { get; set; }
}

/// <summary>
/// 组织单位
/// </summary>
[Table("organization"), DisplayName("组织单位"), Index(nameof(Name), IsUnique = true), Index(nameof(Code), IsUnique = true)]
public abstract class Organization<TKey> : Group<TKey>, IIdentity<TKey>, IParent<TKey>, IEntitySetWithCreateAndUpdate<TKey> where TKey : IConvertible
{
    /// <summary>
    /// 单位编号, 单位注册号, 单位代码, 统一社会信用代码等
    /// </summary>
    [Column("code"), DisplayName("单位编号"), MaxLength(36), Excel]
    public virtual string? Code { get; set; }
    /// <summary>
    /// 单位地址
    /// </summary>
    [Column("address"), DisplayName("单位地址"), MaxLength(128), Excel]
    public virtual string? Address { get; set; }
    /// <summary>
    /// 注册日期
    /// </summary>
    [Column("registration_date"), DisplayName("注册日期"), Excel]
    public virtual DateOnly? RegistrationDate { get; set; }
    /// <summary>
    /// 证件编号
    /// </summary>
    [Column("credential_id"), DisplayName("证件编号"), MaxLength(36), Excel]
    public virtual string? CredentialId { get; set; }
}